﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="vlaev_tunnistus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(VlaevTunnistus))]
    public class VlaevTunnistusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IVlaevTunnistus clazz;
        
        public VlaevTunnistusSerializer(IVlaevTunnistus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("tunnistus_nr");
            if (clazz.TunnistusNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TunnistusNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TunnistusNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("viimane_tunnistus");
            if (clazz.ViimaneTunnistus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ViimaneTunnistus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ViimaneTunnistus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("isikukood");
            if (clazz.Isikukood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikukood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikukood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("eesnimi");
            if (clazz.Eesnimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eesnimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("perenimi");
            if (clazz.Perenimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Perenimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Perenimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("synniaeg");
            if (clazz.Synniaeg!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Synniaeg))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Synniaeg");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("synnikoha_riik");
            if (clazz.SynnikohaRiik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SynnikohaRiik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SynnikohaRiik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("haldusyksus");
            if (clazz.Haldusyksus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Haldusyksus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Haldusyksus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("aadress");
            if (clazz.Aadress!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Aadress))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Aadress");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("soidupiirkond");
            if (clazz.Soidupiirkond!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Soidupiirkond))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Soidupiirkond");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("valja_antud");
            if (clazz.ValjaAntud!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.ValjaAntud))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ValjaAntud");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kehtib");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Kehtib))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("olek");
            if (clazz.Olek!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Olek))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Olek");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "tunnistus_nr")) {
                goto tunnistus_nr;
            }
            else {
                if ((Reader.LocalName == "viimane_tunnistus")) {
                    goto viimane_tunnistus;
                }
                else {
                    if ((Reader.LocalName == "isikukood")) {
                        goto isikukood;
                    }
                    else {
                        if ((Reader.LocalName == "eesnimi")) {
                            goto eesnimi;
                        }
                        else {
                            if ((Reader.LocalName == "perenimi")) {
                                goto perenimi;
                            }
                            else {
                                if ((Reader.LocalName == "synniaeg")) {
                                    goto synniaeg;
                                }
                                else {
                                    if ((Reader.LocalName == "synnikoha_riik")) {
                                        goto synnikoha_riik;
                                    }
                                    else {
                                        if ((Reader.LocalName == "haldusyksus")) {
                                            goto haldusyksus;
                                        }
                                        else {
                                            if ((Reader.LocalName == "aadress")) {
                                                goto aadress;
                                            }
                                            else {
                                                if ((Reader.LocalName == "soidupiirkond")) {
                                                    goto soidupiirkond;
                                                }
                                                else {
                                                    if ((Reader.LocalName == "valja_antud")) {
                                                        goto valja_antud;
                                                    }
                                                    else {
                                                        if ((Reader.LocalName == "kehtib")) {
                                                            goto kehtib;
                                                        }
                                                        else {
                                                            if ((Reader.LocalName == "olek")) {
                                                                goto olek;
                                                            }
                                                            else {
                                                                return;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        tunnistus_nr:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>tunnistus_nr");
            }
            clazz.TunnistusNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tunnistus_nr")).Value;
            goto START;
        viimane_tunnistus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>viimane_tunnistus");
            }
            clazz.ViimaneTunnistus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("viimane_tunnistus")).Value;
            goto START;
        isikukood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>isikukood");
            }
            clazz.Isikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isikukood")).Value;
            goto START;
        eesnimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>eesnimi");
            }
            clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eesnimi")).Value;
            goto START;
        perenimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>perenimi");
            }
            clazz.Perenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("perenimi")).Value;
            goto START;
        synniaeg:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>synniaeg");
            }
            clazz.Synniaeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("synniaeg")).Value;
            goto START;
        synnikoha_riik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>synnikoha_riik");
            }
            clazz.SynnikohaRiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("synnikoha_riik")).Value;
            goto START;
        haldusyksus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>haldusyksus");
            }
            clazz.Haldusyksus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("haldusyksus")).Value;
            goto START;
        aadress:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>aadress");
            }
            clazz.Aadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadress")).Value;
            goto START;
        soidupiirkond:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>soidupiirkond");
            }
            clazz.Soidupiirkond = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("soidupiirkond")).Value;
            goto START;
        valja_antud:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>valja_antud");
            }
            clazz.ValjaAntud = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valja_antud")).Value;
            goto START;
        kehtib:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>kehtib");
            }
            clazz.Kehtib = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("kehtib")).Value;
            goto START;
        olek:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>vlaev_tunnistus>olek");
            }
            clazz.Olek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("olek")).Value;
            goto START;
        }
    }
}
